import request from '@/utils/request'

export const settingsApi = {
  // 系统设置相关
  getSystemSettings() {
    return request.get('/settings/system')
  },

  updateSystemSettings(settings) {
    return request.put('/settings/system', settings)
  },

  resetSystemSettings() {
    return request.post('/settings/system/reset')
  },

  // 应用配置
  getAppConfig() {
    return request.get('/settings/app')
  },

  updateAppConfig(config) {
    return request.put('/settings/app', config)
  },

  // 主题设置
  getThemeSettings() {
    return request.get('/settings/theme')
  },

  updateThemeSettings(theme) {
    return request.put('/settings/theme', theme)
  },

  getThemeList() {
    return request.get('/settings/themes')
  },

  uploadTheme(themeFile) {
    return request.post('/settings/themes/upload', themeFile)
  },

  deleteTheme(themeId) {
    return request.delete(`/settings/themes/${themeId}`)
  },

  // 语言和本地化
  getLanguageSettings() {
    return request.get('/settings/language')
  },

  updateLanguageSettings(language) {
    return request.put('/settings/language', language)
  },

  getSupportedLanguages() {
    return request.get('/settings/languages')
  },

  getTranslations(language) {
    return request.get(`/settings/translations/${language}`)
  },

  updateTranslations(language, translations) {
    return request.put(`/settings/translations/${language}`, translations)
  },

  // 安全设置
  getSecuritySettings() {
    return request.get('/settings/security')
  },

  updateSecuritySettings(security) {
    return request.put('/settings/security', security)
  },

  // 密码策略
  getPasswordPolicy() {
    return request.get('/settings/password-policy')
  },

  updatePasswordPolicy(policy) {
    return request.put('/settings/password-policy', policy)
  },

  // 邮件设置
  getEmailSettings() {
    return request.get('/settings/email')
  },

  updateEmailSettings(email) {
    return request.put('/settings/email', email)
  },

  testEmailSettings(testData) {
    return request.post('/settings/email/test', testData)
  },

  // 短信设置
  getSMSSettings() {
    return request.get('/settings/sms')
  },

  updateSMSSettings(sms) {
    return request.put('/settings/sms', sms)
  },

  testSMSSettings(testData) {
    return request.post('/settings/sms/test', testData)
  },

  // 文件存储设置
  getStorageSettings() {
    return request.get('/settings/storage')
  },

  updateStorageSettings(storage) {
    return request.put('/settings/storage', storage)
  },

  testStorageConnection(storageType) {
    return request.post('/settings/storage/test', { type: storageType })
  },

  // 缓存设置
  getCacheSettings() {
    return request.get('/settings/cache')
  },

  updateCacheSettings(cache) {
    return request.put('/settings/cache', cache)
  },

  clearCache(cacheType) {
    return request.post('/settings/cache/clear', { type: cacheType })
  },

  getCacheStats() {
    return request.get('/settings/cache/stats')
  },

  // 日志设置
  getLogSettings() {
    return request.get('/settings/logs')
  },

  updateLogSettings(logs) {
    return request.put('/settings/logs', logs)
  },

  getLogLevels() {
    return request.get('/settings/log-levels')
  },

  // 备份设置
  getBackupSettings() {
    return request.get('/settings/backup')
  },

  updateBackupSettings(backup) {
    return request.put('/settings/backup', backup)
  },

  // API 设置
  getAPISettings() {
    return request.get('/settings/api')
  },

  updateAPISettings(api) {
    return request.put('/settings/api', api)
  },

  generateAPIKey(name) {
    return request.post('/settings/api-keys', { name })
  },

  revokeAPIKey(keyId) {
    return request.delete(`/settings/api-keys/${keyId}`)
  },

  getAPIKeys() {
    return request.get('/settings/api-keys')
  },

  // 第三方集成设置
  getIntegrationSettings() {
    return request.get('/settings/integrations')
  },

  updateIntegrationSettings(integration) {
    return request.put('/settings/integrations', integration)
  },

  testIntegration(integrationType, config) {
    return request.post('/settings/integrations/test', {
      type: integrationType,
      config
    })
  },

  // 维护设置
  getMaintenanceSettings() {
    return request.get('/settings/maintenance')
  },

  updateMaintenanceSettings(maintenance) {
    return request.put('/settings/maintenance', maintenance)
  },

  enableMaintenanceMode(message) {
    return request.post('/settings/maintenance/enable', { message })
  },

  disableMaintenanceMode() {
    return request.post('/settings/maintenance/disable')
  },

  // 性能设置
  getPerformanceSettings() {
    return request.get('/settings/performance')
  },

  updatePerformanceSettings(performance) {
    return request.put('/settings/performance', performance)
  },

  // 导入导出设置
  exportSettings() {
    return request.get('/settings/export')
  },

  importSettings(settingsFile) {
    return request.post('/settings/import', settingsFile)
  },

  validateSettingsFile(settingsFile) {
    return request.post('/settings/validate', settingsFile)
  },

  // 设置历史
  getSettingsHistory() {
    return request.get('/settings/history')
  },

  getSettingsDiff(historyId) {
    return request.get(`/settings/history/${historyId}/diff`)
  },

  restoreSettings(historyId) {
    return request.post(`/settings/history/${historyId}/restore`)
  },

  // 配置模板
  getConfigTemplates() {
    return request.get('/settings/templates')
  },

  createConfigTemplate(template) {
    return request.post('/settings/templates', template)
  },

  applyConfigTemplate(templateId) {
    return request.post(`/settings/templates/${templateId}/apply`)
  },

  deleteConfigTemplate(templateId) {
    return request.delete(`/settings/templates/${templateId}`)
  }
}
